/**
 * Fibonaci
 * @author hoang.pt
 * @version $Id: Fibonaci.java 143 2010-09-07 04:51:29Z phantichhoang $
 */

package homework.homework2.problem1;

/**
 * Fibonaci entity
 * @author hoang.pt
 */
public class Fibonaci {

    /**
     * @var boolean
     */
    boolean flag = false;
    
    /**
     * @var int temp1
     */
    int temp1 = 0;
    
    /**
     * @var int temp2
     */
    
    int temp2 = 1;
    
    /**
     * @var int Fibo
     */
    int fiboNumber = 1;

    /**
     * constructor
     */
    public Fibonaci() {
    }

    /**
     * Display Series
     * @author hoang.pt
     */
    public void changeState() {

        //change temp1, temp2
        this.temp1 = temp2;
        this.temp2 = fiboNumber;
        this.fiboNumber = temp1 + temp2;
    }

    /**
     * Gen Fibo number
     * @author hoang.pt
     * @return int
     */
    public void displayFibo() {
        System.out.println(fiboNumber);
        
        try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
    }

    /**
     * Display
     * @author hoang.pt
     */
    public void displayOddAndEven() {

        //state indicate odd or even
        String state;
        state = (fiboNumber % 2 == 0) ? "even" : "odd";

        //display
        System.out.println("... thus fibo " + fiboNumber + " is " + state);
        
        //occupy o.5s
        try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
        
        
    }
    
    /**
     * display series
     * @author hoang.pt
     */
    public void displayFiboSeries() {
    	//run forever
    	while (true) {
        	//line 1
        	displayFibo();
        	
        	//line 2
        	displayOddAndEven();
        	
        	//gen next fibo
        	changeState();
        	
        	try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
    	}
    	
    }
}
